﻿using mozhi.smarterp.AuthorCenter.Roles;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;

namespace mozhi.smarterp.AuthorCenter.Controllers
{
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IdentityRoleController))]
    public class CustomIdentityRoleController : IdentityRoleController
    {
        private ICustomIdentityRoleAppService _appService;

        public CustomIdentityRoleController(ICustomIdentityRoleAppService roleAppService) : base(roleAppService)
        {
            _appService = roleAppService;
        }

        public override async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(GetIdentityRolesInput input)
        {
            var filter = new IdentityRoleFilter();
            filter.Sorting = input.Sorting;
            filter.MaxResultCount = input.MaxResultCount;
            filter.SkipCount = input.SkipCount;
            filter.Filter = input.Filter;

            var typeParamter = HttpContext.Request.Query["roleType"].ToString();

            int roleType = 0;

            if (int.TryParse(typeParamter, out roleType))
                filter.RoleType = roleType;

            return await _appService.GetListAsync(filter);
        }
    }
}
